<!--
 * @Author: 詹真琦(legendryztachi@gmail.com)
 * @Date: 2022-03-25 11:20:34
 * @LastEditors: 詹真琦(legendryztachi@gmail.com)
 * @LastEditTime: 2022-04-21 09:34:47
 * @FilePath: \code\cwp-front\pc-collaboration\src\handles\handle-list\summary\modules\supervise-set\index.vue
 * @Description: 督办设置
-->
<template>
    <div id="supervise-setting">
        <Supervise :supervise="data" @update="update" />
    </div>
</template>
<script>
    import { useSuperviseSetStore, INIT_DATA } from '@/store/modules/summary/supervise-set';
    import { mapState, mapActions } from 'pinia';

    import Supervise from '@/components/atom/supervise/index.vue';
    //督办数据字段
    const SUPERVISE_KEYS = Object.keys(INIT_DATA);
    export default {
        name: 'SuperviseSetting',
        components: { Supervise },
        data() {
            return {
                data: { ...INIT_DATA },
            };
        },
        computed: {
            ...mapState(useSuperviseSetStore, ['detailId', 'originData'].concat(SUPERVISE_KEYS)),
        },
        created() {
            //把上下文传递给父级
            this.$emit('getContext', this);
            //设置初始数据
            //             superviseTitle: "231231"
            // supervisorIds: "5008328947798656782,1341741964014732581"
            // supervisorNames: "cm1(cm)、只有你会"

            //设置初始数据
            SUPERVISE_KEYS.forEach((key) => {
                this.data[key] = this[key];
            });
        },
        methods: {
            ...mapActions(useSuperviseSetStore, ['setSuperviseData']),
            //数据更新
            update(data) {
                Object.entries(data).forEach(([k, v]) => {
                    this.data[k] = v;
                });
            },
            //确定设置数据
            confirm() {
                //数据是否改动。如果是第一次，就直接为true
                const isModifySupervise = this.detailId
                    ? SUPERVISE_KEYS.some((key) => this.originData[key] !== this.data[key])
                    : true;
                this.setSuperviseData(Object.assign(this.data, { isModifySupervise }));
            },
        },
    };
</script>
<style lang="scss" scoped>
    #supervise-setting {
        margin-top: 40px;
    }
</style>
<style lang="scss">
    .supervise-setting-confirm-container {
        .ant-modal-confirm-body {
            > i.anticon-question-circle {
                display: none;
            } 
        }
    }
</style>
